package com.heima.admin.service.Impl;

import com.heima.admin.dto.NewsAuthDto;
import com.heima.admin.dto.WmNews;
import com.heima.admin.feign.WeMediaFeign;
import com.heima.admin.service.IAdAuthService;
import com.heima.admin.vo.WmNewsVo;
import com.heima.common.dto.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IAdAuthServiceImpl implements IAdAuthService {

    @Autowired
    private WeMediaFeign weMediaFeign;

    @Override
    public ResponseResult findAuthList(NewsAuthDto dto) {
        return weMediaFeign.findPageByName(dto);
    }

    @Override
    public ResponseResult<WmNewsVo> getOne(Integer id) {
        return weMediaFeign.findNewsVoById(id);
    }

    @Override
    public ResponseResult authPassorFail(NewsAuthDto dto) {
        ResponseResult<WmNews> responseResult = weMediaFeign.getById(dto.getId());
        if (responseResult.getCode().equals(AppHttpCodeEnum.SUCCESS.getCode())){
            WmNews wmNews = responseResult.getData();
            if (dto.getStatus()==4){
                wmNews.setStatus(4);
            }
            if (dto.getStatus()==2){
                wmNews.setStatus(2);
                wmNews.setReason(dto.getMsg());
            }
            weMediaFeign.updateById(wmNews);
        }
        return ResponseResult.okResult();
    }
}
